<?php
//登录
if(!defined('IN_T')){
   die('hacking attempt');
}

if(empty($_POST)){
   //todo
}
else{
   $name = Common::sfilter($_REQUEST['name']);
   $passwd = Common::sfilter($_REQUEST['passwd']);
   $remember = intval($_REQUEST['remember']);
   $res['status'] = 0;
   $company = $Db->query("select * from ".$Base->table('company')." where name='$name' and passwd='".Common::encrypt($passwd)."'","Row");

   if(!empty($company)){
      if($company['is_not'] == 0){
         $res['msg'] = '账号被禁用';
      }
      else{
       //赋值到session
        $_SESSION['company'] = array(
         'id' => $company['id'],
         'name' => $company['name'],
         'p_id'=>$company['p_id'],
         'priv' => $Json->decode($company['privileges']),
         'c_id'=>get_company_id(),
        );
         //7天内免登录
        if($remember==1){
          //admin_name,passwd连接加密
          $hashcode = Common::encrypt($name.Common::encrypt($passwd));
          setcookie("company[id]",$company['id'],Common::gmtime()+7*60*60*24,'/');
         setcookie("company[hashcode]",$hashcode,Common::gmtime()+7*60*60*24,'/');   
        }
         $res['status'] = 1;
        $res['msg']= '登录成功，跳转...';
        $res['href'] = '/'.COMPANY_PATH.'/?m=index';
      }
     
   }
   else{
      $res['msg'] = '账号密码不正确';
   }
   echo $Json->encode($res);
   exit;
}
?>